package com.gxa.controller.general;

import com.alibaba.excel.EasyExcel;
import com.gxa.common.R;
import com.gxa.service.ImportExcelService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class ImportExcelController {

    @Autowired
    private ImportExcelService importExcelService;

    //excel批量导入数据
    @PostMapping(value = "/import")
    @ResponseBody
    public R storageService(@RequestParam("file") MultipartFile file) {
        R r = new R();
        try {
            importExcelService.dealFile(file);
            r.setCount(200);
            r.setMsg("导入成功！");
        } catch (Exception e) {
            r.setCode(500);
            r.setMsg("系统异常,导入失败,请联系管理员");
        }
        return r;
    }
}
